﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>

<script type="text/javascript" src="../../Content/Js/Ajax.js"></script>
<script type="text/javascript" src="../../Content/Js/HomePage.js"></script>

    


    
<script type="text/javascript" src="../../Content/ablum/ablum/jquery-1.4.3.min.js"></script>
<script type="text/javascript" src="../../Content/ablum/ablum/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
<script type="text/javascript" src="../../Content/ablum/ablum/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<link rel="stylesheet" type="text/css" href="../../Content/ablum/ablum/fancybox/jquery.fancybox-1.3.4.css" media="screen">

 

<script type="text/javascript">
    $(document).ready(function () {

        var focus = [];
        var focusindex = -1;


        function changefocus() {
            if (focus[focusindex].Type == 0) {
                $('div#focusfeeling div.middle-drop').html('<div class="imagepart"><img src="' + focus[focusindex].ImagePath + '" class="headimage" data="' + focus[focusindex].UserId + '" onclick="PublicAlbum(this)";></div><div class="trendcontent"><p class="headline"><a href="/FriendTrend/Friend?friendId=' + focus[focusindex].UserId + '"><span>' + focus[focusindex].Name + '</span></a>发表文章<a target="_blank" class="pointer" onclick="SeeArticle(this);"  articledata="' + focus[focusindex].Link + '"><span>' + focus[focusindex].Title + '</span></a></p><p class="contentline"></p><p>' + focus[focusindex].Content + '</p><p></p><p class="commentline"><span>' + focus[focusindex].CreateTime + '</span></p></div>');
            } else if (focus[focusindex].Type == 1) {
                $('div#focusfeeling div.middle-drop').html('<div class="imagepart"><img src=" ' + focus[focusindex].ImagePath + '" class="headimage" data="' + focus[focusindex].UserId + '" onclick="PublicAlbum(this);"></div><div class="trendcontent"><p class="headline"><a href="/FriendTrend/Friend?friendId=' + focus[focusindex].UserId + '"><span> ' + focus[focusindex].Name + '</span></a>分享链接<a target="_blank"   href=" ' + focus[focusindex].Link + '"><span> ' + focus[focusindex].Title + '</span></a></p><p class="contentline"></p><p>' + focus[focusindex].Content + '</p><p></p><p class="commentline"><span> ' + focus[focusindex].CreateTime + '</span></p></div>');
            } else if (focus[focusindex].Type == 2) {
                $('div#focusfeeling div.middle-drop').html('<div class="imagepart"><img src=' + focus[focusindex].ImagePath + ' class="headimage" data="' + focus[focusindex].UserId + '" onclick="PublicAlbum(this);"></div><div class="trendcontent"><p class="headline"><a href="/FriendTrend/Friend?friendId=' + focus[focusindex].UserId + '"><span>' + focus[focusindex].Name + '</span></a>上传相片到<a target="_blank" class="pointer"   onclick="AlbumPhoto(this);"  data="' + focus[focusindex].Link + '"><span>' + focus[focusindex].Title + '</span></a></p><p class="contentline"><a><dd class="pointer" onclick="BigPhoto(this);" src="' + focus[focusindex].PhotoPath + '">点击此处获取图片</dd></p><p class="commentline"><span>' + focus[focusindex].CreateTime + '</span></p></div>');
            } else if (focus[focusindex].Type == 3) {
                $('div#focusfeeling div.middle-drop').html('<div class="imagepart"><img src="' + focus[focusindex].ImagePath + ' " class="headimage" data="' + focus[focusindex].UserId + '" onclick="PublicAlbum(this);"></div><div class="trendcontent"><p class="headline"><a href="/FriendTrend/Friend?friendId=' + focus[focusindex].UserId + '"><span>' + focus[focusindex].Name + '</span></a>记下心情<a target="_blank"   href="' + focus[focusindex].Link + '"><span>' + focus[focusindex].Title + '</span></a></p><p class="contentline">' + focus[focusindex].Content + ' </p><p class="commentline"><span>' + focus[focusindex].CreateTime + '</span></p></div>');
            }
        }

        $('#lastfocus,#nextfocus').click(function () {


            if (this.id == 'lastfocus') focusindex--; else focusindex++;
            if (focusindex < 0) focusindex = 0;
            if (focusindex >= focus.length) {
                var createtime = $('div.middle-drop p.commentline span:first').html();
                $.ajax({ url: '/Home/MoreFocusFeelingJson', data: { lastTime: createtime }, dataType: 'json', type: 'post', success: function (data) {
                   
                    focus = focus.concat(data);
                    if (focusindex > focus.length) focusindex = focus.length - 1;
                    changefocus();
                } //end success

                });
                //end of ajax

            }
            else
                changefocus();
        });


    });            //end of document
</script>

<%--更多关注动态--%>

<script type="text/javascript">
    $(document).ready(function () {

        $('#getmoretrends').click(function () {

            //把时间填补完成;
            var createtime = $('div.trend:last div.trendcontent p.commentline span:first').html();



            $.ajax({ url: '/Home/MoreTrendJson', data: { lastTime: createtime }, dataType: 'json', type: 'post', success: function (data) {
                if (data.length > 0) {
                    for (i in data) {
                        if (data[i].Type == 0) {
                            $('div#trendlist').children('div:last').after('<div class="clear"></div><div class="trend" data="' + data[i].Id + '"><div class="imagepart"><img src="' + data[i].ImagePath + '" class="headimage" data="' + data[i].UserId + '" onclick="PublicAlbum(this);"></div><div class="trendcontent"><p class="headline"><a href="/FriendTrend/Friend?friendId=' + data[i].UserId + '"><span>' + data[i].Name + '</span></a>发表文章<a target="_blank" class="pointer" onclick="SeeArticle(this);" articledata="' + data[i].Link + '"><span>' + data[i].Title + '</span></a></p><p class="contentline"></p><p>' + data[i].Content + '</p><p></p><p class="commentline"><span>' + data[i].CreateTime + '</span><span onclick="GetComment(this);" class="articlecm pointer">评论（' + data[i].CommentCount + '）</span></p></div></div>');
                        } else if (data[i].Type == 1) {
                            $('div#trendlist').children('div:last').after('<div class="clear"></div><div class="trend" data="' + data[i].Id + '"><div class="imagepart"><img src=" ' + data[i].ImagePath + '" class="headimage" data="' + data[i].UserId + '" onclick="PublicAlbum(this);"></div><div class="trendcontent"><p class="headline"><a href="/FriendTrend/Friend?friendId=' + data[i].UserId + '"><span> ' + data[i].Name + '</span></a>分享链接<a target="_blank"   href=" ' + data[i].Link + '"><span> ' + data[i].Title + '</span></a></p><p class="contentline"></p><p>' + data[i].Content + '</p><p></p><p class="commentline"><span> ' + data[i].CreateTime + '</span><span onclick="GetComment(this);" class="pointer">评论（' + data[i].CommentCount + '）</span></p></div></div>');
                        } else if (data[i].Type == 2) {
                            $('div#trendlist').children('div:last').after('<div class="clear"></div><div class="trend" data="' + data[i].Id + '"><div class="imagepart"><img src=' + data[i].ImagePath + ' class="headimage" data="' + data[i].UserId + '" onclick="PublicAlbum(this);"></div><div class="trendcontent"><p class="headline"><a href="/FriendTrend/Friend?friendId=' + data[i].UserId + '"><span>' + data[i].Name + '</span></a>上传相片到<a target="_blank" class="pointer" onclick="AlbumPhoto(this);"  data="' + data[i].Link + ' "><span>' + data[i].Title + '</span></a></p><p class="contentline"><a><img class="photo" onclick="BigPhoto(this);" src="' + data[i].PhotoPath + '"></a></p><p class="commentline"><span>' + data[i].CreateTime + '</span><span>相片（' + data[i].CommentCount + '）</span></p></div></div>');
                        } else if (data[i].Type == 3) {
                            $('div#trendlist').children('div:last').after('<div class="clear"></div><div class="trend" data="' + data[i].Id + '"><div class="imagepart"><img src="' + data[i].ImagePath + ' " class="headimage" data="' + data[i].UserId + '" onclick="PublicAlbum(this);"><img src="' + ChangeFeelingImage(data[i].Title) + '" class="feelimage"></div><div class="trendcontent"><p class="headline"><a href="/FriendTrend/Friend?friendId=' + data[i].UserId + '"><span>' + data[i].Name + '</span></a>记下心情<a target="_blank"   href="' + data[i].Link + '"><span>' + data[i].Title + '</span></a></p><p class="contentline">' + data[i].Content + ' </p><p class="commentline"><span>' + data[i].CreateTime + '</span><span onclick="GetComment(this);" class="feelingcm pointer">评论（' + data[i].CommentCount + '）</span></p></div></div>');
                        }

                    }
                }
                else {
                    $('#getmoretrends').html('无更多动态');
                }
            } //success
            });
        });




    });         //end of document

</script>

<%--更多好友动态--%>





<%--分享--%>

<script type="text/javascript">
    function GetComment(e) {

        var where = $(e).parents('div.trend');
        var type;
        if ($(e).hasClass("articlecm")) type = 0;
        if ($(e).hasClass("feelingcm")) type = 3;


        var id = where.attr('data');

        if (where.next('div:first').hasClass('commentlist')) return;
        $.ajax({ url: '/FriendTrend/GetCommentListJson', data: { Id: id, type: type }, dataType: 'json', type: 'post', success: function (data) {
            var html = '<div class="commentlist"><div class="commenthead"></div><div class="comment">';
            for (i in data) html = html + '<div class="tt"><div class="close"><a href="javascript:void(0);"><img src="../Content/Images/mainpage/X.png" alt="关闭"></a></div><div class="smallimagepart"><img class="smallheadimage pointer" src="' + data[i].ImagePath + '" onclick="PublicAlbum(this)" data="'+data[i].UserId+'"></div><div class="commentcontent"><div class="headline"><a target="_blank" href="/FriendTrend/Friend?friendId='+data[i].UserId+'">' + data[i].Name + '  ' + data[i].CreateTime + '</div><div class="contentline">' + data[i].Content + '</div></div><div class="commentclear"></div></div>';
            html = html + '<div class="reply"><textarea class="com commentareafocusout" >按Enter发表评论……</textarea></div></div>';
            where.after(html);


            where.next('div.commentlist').find('div.reply textarea').focus(function () {
                if ($(this).val() != '按Enter发表评论……') return;
                $(this).val('').removeClass('commentareafocusout').addClass('commentareafocus');
            }).focusout(function () {
                if ($(this).val() != '') return;
                $(this).val('按Enter发表评论……').removeClass('commentareafocus').addClass('commentareafocusout');
            }).bind('keydown', function (e) {
                if (e.keyCode == 13) {
                    var comment = $(this).val();
                    var ee = $(this);
                    //begin
                    if (comment.length <= 0)
                        return;
                    if (comment.length > 140) {
                        cAlert('评论不能长于140字');
                        return;
                    }
                    
                    $.ajax({
                        url: '/FriendTrend/AddComment',
                        type: 'POST',
                        data: { Id: id, type: type, comment: comment },
                        success: function (data) {
                                                     
                            ee.val('');
                            ee.focus(1,function(){this.blur()});
                            

                             ee.before('<div class="tt"><div class="close"><a href="javascript:void(0);"><img src="../Content/Images/mainpage/X.png" alt="关闭"></a></div><div class="smallimagepart"><img class="smallheadimage" src="' + data.ImagePath + '"></div><div class="commentcontent"><div class="headline">' + data.Name + '  ' + data.CreateTime + '</div><div class="contentline">' + data.Content + '</div></div><div class="commentclear"></div></div>').slideDown('slow');
                             where.next('div.commentlist').css('height', '0').slideDown('slow');
                             where.next('div.commentlist').find('div.close a').click(function () {
                                 if ($(this).parents('div.commentlist').find('div').length == 0)
                                     $(this).parents('div.commentlist').slideUp();
                                 else
                                     $(this).parents('div.tt').slideUp();
                             });
                        },
                        error: function () { Error(); }
                    });
                    //emd

                }
            });


            where.next('div.commentlist').css('height', '0').slideDown('slow');
            where.next('div.commentlist').find('div.close a').click(function () {
                if ($(this).parents('div.commentlist').find('div').length == 0)
                    $(this).parents('div.commentlist').slideUp();
                else
                    $(this).parents('div.tt').slideUp();
            });
        }
        });


}


</script>

<%--获得评论  评论--%>

<script type="text/javascript">
    function ChangeFeelingImage(feel) {
        return "../../Content/Images/feeling/" + feel + ".jpg";
    }
</script>

<script type="text/javascript">
    function SeeArticle(e) {
        var art = $(e).attr('articledata');
        var begin = art.indexOf('articleId=');
        var articleId = art.substring(begin + "articleId=".length);
        
        $.ajax({
            url: '/FriendTrend/FriendArticle',
            data: { articleId: articleId },
            type: 'POST',
            success: function (data) {
                if (data == null)
                    cAlert('文章已经被删除');
                else {
                    var dialogname = "article";
                    var content = '<div id="article"><div class="trend"><p class="title"><span>'+data.Title+'</span></p><div class="clear"></div><p class="commentline">'+data.CreateTime+'</p><div class="articlecontent">'+data.Content+'</div></div></div>';
                    $('body').append(content);
                    $('#' + dialogname).dialog({ autoOpen: true, width: 800, height:600, resizable: false, modal: true });
                } //end of if
            },
            error: function () { Error(); }

        });          //end ajax
    }
</script>